package com.chalk.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.chalk.dao.SportEventDao;
import com.chalk.model.SportEvent;
import com.chalk.service.SportEventService;

import com.chalk.service.VenueAndSeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author glq
 * @since 2020-12-10
 */

@Service
public class SportEventServiceImpl extends ServiceImpl<SportEventDao, SportEvent> implements SportEventService {

    @Autowired
    VenueAndSeService venueAndSeService;

    @Override
    public int addSportEvent(SportEvent entity) {
        return baseMapper.insert(entity);
    }

    @Override
    public int updateSportEvent(SportEvent entity) {
        return baseMapper.updateById(entity);
    }


    @Override
    public int deleteSportEvent(Integer id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public Page<SportEvent> getSportEventForPage(Integer page, Integer size) {
        EntityWrapper<SportEvent> wrapper = new EntityWrapper<>();
        wrapper.eq("is_delete", 0);
        return selectPage(new Page<SportEvent>(page, size), wrapper);
    }


    @Override
    public List<SportEvent> getSportEvents(Integer venueId) {
        EntityWrapper<SportEvent> wrapper = new EntityWrapper<>();
        wrapper.eq("is_delete", 0);
        List<Integer> integers = venueAndSeService.getSportEventsByVenueId(venueId);
        if (integers.size() == 0) {
            return new ArrayList<SportEvent>();
        }
        wrapper.in("se_id",integers);
        return selectList(wrapper);
    }
}
